package com.cn.project.rabbirMQ;
import com.alibaba.fastjson.JSONObject;
import com.cn.common.pojo.Weekly;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
@Component
@RabbitListener(queues = {"LeaderQueue"})
public class WeeklyReceiver {
    @Autowired
    private JavaMailSender mailSender;
    @RabbitHandler
    public void process(String msg) {
        SimpleMailMessage message = new SimpleMailMessage();
        try {
            Weekly weekly = JSONObject.parseObject(msg, Weekly.class);
            message.setFrom("2681423553@qq.com");
            message.setTo("2681423553@qq.com");
            message.setSubject(weekly.getReporter());
            message.setText(weekly.getDate()+"\n"+weekly.getContent());
            mailSender.send(message);

//            System.out.println(weekly);
        }catch (Exception e){
            e.printStackTrace();
        }
        return;
    }
}